home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / olrdrs / nnrnews1.zip / NNRNEWS.PAS < prev   
Pascal/Delphi Source File  |  1994-06-10  |  17KB  |  399 lines

  1. {
  2. NNRNEWS.PAS ver. 1.00 - May 23, 1994. Programmed in Turbo Pascal 6.0 by
  3.  
  4.   Henrik Rosen¢  (*)
  5. --
  6. | Henrik Rosen¢, MSc.         |    Tel: + 45 35 36 52 76    | East or West, |
  7. | N¢rrebrogade 49C, 1.tv.     |    FAX: + 45 35 26 25 93    | Cyberspace is |
  8. | 2200 Copenhagen N - DENMARK | e-mail: hero@login.dkuug.dk | best   - HeRo |
  9.  
  10. NNRNEWS.PAS Copyright (c) 1994 Henrik Rosen¢.
  11.  
  12. License conditions:
  13. This program is freeware and distributed as a TP 6.0 source file.
  14. I do not take any responsibility for the consequences of compiling or
  15. running the program. Alteration and redistribution is allowed, as long
  16. as the file is only altered below the following line.
  17. --------------------------------------------------------------------------
  18.  
  19.   NNRNEWS convertes files saved by nn into rnews-batches (according
  20.   to RFC-1036 section 4.3), by inserting the '#! rnews <x>'-line before
  21.   the headers of all the postings in the file. When saved by nn, the
  22.   messages are simply separated by an empty line. It has been tested,
  23.   that Yarn v0.65 can import these rnews-batches.
  24.  
  25.   The program requires access to FLIP.EXE, to work!
  26.   (FTP or download FLIP from somewhere, for instance as
  27.    textutil/flip1exe.zip at SimTel mirrors.)
  28.  
  29.   The nnrnews command:
  30.  
  31.       nnrnews [searchstring [directory]]
  32.  
  33.         searchstring  The files to be processed ex. *.doc.
  34.                       Default is *.*
  35.                       (At least on DR DOS 6.0 *.* does not work!)
  36.  
  37.         directory     The directory to be searched for files to convert.
  38.                       Default is current directory on default drive.
  39.  
  40. When compiled in TP 6.0, this program cuts down lines to 255 characters.
  41. Some header lines (especially Path: and Xref:, but also Newsgroups:) are
  42. longer than 255 characters, and are damaged.
  43. Lines that where cut, are copied to the file 'cutlines.uvy', for manual
  44. evaluation of the damage.
  45. Anybody with TP 7.0 are encouraged to compile a version of the program,
  46. that does not cut any lines.
  47.  
  48.   All <space>-characters in the end of any line is removed in the process.
  49.   This feature is an integrated part of the whole algorithm.
  50.   The program allows the file to start with whatever before the first
  51.   news-message, and moves that to 'crapfile.uvy'.
  52.  
  53.   The program detects the starting of a new message by the following
  54.   criteria:
  55.   After an empty line, all the required headers (according to RFC-1036)
  56.   are found among the headers before the next empty line (or max. 50 lines).
  57.   The required headers are:
  58.   "From:", "Date:", "Newsgroups:", "Subject:", "Message-ID:" and "Path:".
  59.  
  60.   This algorithm is nearly 100% sure of detecting the start of a message,
  61.   but:
  62.   1. If a message contains a forwarded message, the forwarded message will
  63.      be regarded as a new message, if the 6 required headers are unchanged
  64.      and there is an empty line just before these headers.
  65.   2. If the first header is very wierd and therefore unknown (see the
  66.      is_header-function), the program will not regard it as the start of
  67.      a new message.
  68.   3. If the block of headers contains an empty line before the 6 required
  69.      headers have been found, the program will not regard it as the start
  70.      of a new message.
  71.  
  72.   The program can _probably_ handle up to 8000 messages in one file,
  73.   depending only on allocated heap. The size of files only depend on the
  74.   diskspace for the temporary copy.
  75.   The program uses 2 passes:
  76.   1. It finds the starting points of messages, places '#! rnews' and
  77.      counts the size of the messages in bytes. These numbers are placed
  78.      in a list chained with pointers.
  79.   2. The numbers in the list are placed in the '#! rnews'-lines.
  80.   Well, there are actually 2 more passes (calling FLIP.EXE):
  81.   Before, all the files are converted to DOS-ASCII, by inserting <Carriage
  82.   Return> at newline (for Turbo Pascal to be able to handle them as text
  83.   files), and in the end they are converted (back) to UNIX-text-format,
  84.   by removing the <Carriage Return>s at all newlines, to create a real
  85.   rnews-batch.
  86.  
  87. (*) (The reason why Danish letters can be used in Turbo Pascal source code,
  88.      is that from the begining as COMPAS Pascal in 1982 (or earlier?), and
  89.      until now, TP has been developed by a Dane, Anders Hejlsberg.
  90.      He programmed the Pascal-compiler in Z80-assembler in his spare time
  91.      while studying Bachelor in Computer Science. I believe that he invented
  92.      the idea of an integrated, interactive program-development environment,
  93.      know called IDE, thereby making the big, clumsy, and time-consuming
  94.      error-recovery procedures obsulete in the compiler.)
  95. }
  96.  
  97. program nnrnews;
  98. {$I-}
  99. {$M 16000,0,65000 }
  100. uses    dos,crt;
  101. type
  102.   int_point = ^longint_rec;
  103.   longint_rec = record
  104.                   count: longint;
  105.                   next: int_point;
  106.                 end;
  107. var
  108.   first_pointer, last_pointer, temp_pointer
  109.                               : int_point;
  110.   empty_line, empty_oldline, is_from, is_date, is_newsg, is_subj, is_mess,
  111.     is_path, all_headers, is_a_header, is_newsfile
  112.                               : boolean;
  113.   infil, udfil, crapfile, cutlinefile
  114.                               : text;
  115.   l, i, str_count             : integer;
  116.   message_counter             : longint;
  117.   streng, streng2, streng3    : string;
  118.   str_arr                     : array[1..50] of string;
  119.   dirinfo                     : searchrec;
  120.  
  121. procedure required_heads(streng:string);
  122. begin
  123.   { The required headers:  "From:", "Date:", "Newsgroups:", "Subject:",
  124.                            "Message-ID:" and "Path:" }
  125.   if copy(streng,1,5)='Path:'        then is_path:=true else
  126.     if copy(streng,1,11)='Newsgroups:' then is_newsg:=true else
  127.       if copy(streng,1,5)='From:'        then is_from:=true else
  128.         if copy(streng,1,5)='Date:'        then is_date:=true else
  129.           if copy(streng,1,8)='Subject:'     then is_subj:=true else
  130.             if copy(streng,1,10)='Message-ID'  then is_mess:=true else
  131.               if copy(streng,1,10)='Message-id'  then is_mess:=true;
  132. end;
  133.  
  134. function is_header(streng:string): boolean;
  135. var is_head : boolean;
  136. { I believe this function is quite time-optimal! }
  137. begin
  138.   if streng='' then  is_head:=false  else
  139.     if copy(streng,1,1)='-' then  is_head:=false  else
  140.       if copy(streng,1,1)=' ' then  is_head:=false  else
  141.         { The required headers:  "From:", "Date:", "Newsgroups:",
  142.           "Subject:", "Message-ID:" and "Path:" }
  143.         if copy(streng,1,5)='Path:' then
  144.           begin is_head:=true; is_path:=true end else
  145.           if copy(streng,1,11)='Newsgroups:' then
  146.             begin is_head:=true; is_newsg:=true end else
  147.             begin
  148.             is_head:=false;
  149.             if copy(streng,1,5)  = 'From:'       then
  150.               begin is_head:=true; is_from:=true end;
  151.             if copy(streng,1,5)  = 'Date:'       then
  152.               begin is_head:=true; is_date:=true end;
  153.             if copy(streng,1,8)  = 'Subject:'    then
  154.               begin is_head:=true; is_subj:=true end;
  155.             if copy(streng,1,10) = 'Message-ID'  then
  156.               begin is_head:=true; is_mess:=true end;
  157.             if copy(streng,1,10) = 'Message-id'  then
  158.               begin is_head:=true; is_mess:=true end;
  159.             if copy(streng,1,5)  = 'Xref:'          then is_head:=true;
  160.             if copy(streng,1,8)  = 'Expires:'       then is_head:=true;
  161.             if copy(streng,1,8)  = 'Control:'       then is_head:=true;
  162.             if copy(streng,1,13) = 'Distribution:'  then is_head:=true;
  163.             if copy(streng,1,9)  = 'Keywords:'      then is_head:=true;
  164.             if copy(streng,1,8)  = 'Summary:'       then is_head:=true;
  165.             if copy(streng,1,9)  = 'Approved:'      then is_head:=true;
  166.             if copy(streng,1,9)  = 'Comments:'      then is_head:=true;
  167.             if copy(streng,1,6)  = 'Lines:'         then is_head:=true;
  168.             if copy(streng,1,13) = 'MIME-Version:'  then is_head:=true;
  169.             if copy(streng,1,13) = 'MIME-version:'  then is_head:=true;
  170.             if copy(streng,1,13) = 'Mime-V